import React, { Component } from 'react';
import style from './index.module.scss';
import {getRecommendListApi} from "@/api/goods"


class index extends Component {

    state={
        page:1,
        count:9,
        recommendList:[]
    }

    componentDidMount(){
        this.getRecommendList()
    }

    // 获取推荐的商品列表
    async  getRecommendList(){
        let res = await getRecommendListApi({
            page:this.state.page,
            count:this.state.count
        });

        if(res.data.code===200){
            this.setState({
                recommendList:res.data.list
            })
        }
    }

    render() {
        return (
            <div className={style.recommend}>
                {
                    this.state.recommendList.map((item, index) => (
                        <div key={index} className={style.recommendBox}>
                            <img className={style.recommendImg} src={item.pic} alt="" />
                            <p className={style.recommendTitle} >{item.name}</p>
                            <p>
                                <span className={style.originalPrice}>原价{item.salesPrice.value}</span>
                            </p>
                            <p className={style.currentPrice}>抢购价 ￥<span>{item.salesPrice.value}</span></p>
                        </div>
                    ))                       
                }
            </div>
        );
    }
}

export default index;